/*
 *  clb_event_profiling.c
 *  DeferredLighting
 *
 *  Created by Holmes Futrell on 2/13/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#include "clb_event_profiling.h"
#include "clb_error.h"

void clb_print_event_profiling_info(cl_event event, const char *description) {
	
	cl_ulong queued, submit, start, end;
	
	cl_int error = CL_SUCCESS;
	error |= clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_QUEUED, sizeof(queued), &queued, NULL);
	error |= clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_SUBMIT, sizeof(submit), &submit, NULL);
	error |= clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, sizeof(start), &start, NULL);
	error |= clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, sizeof(end),  &end, NULL);

	if ( error == CL_PROFILING_INFO_NOT_AVAILABLE ) {
		printf("profiling information not available (CL_PROFILING_INFO_NOT_AVAILABLE), did you enable profiling on the command queue?\n");
		return;
	}
	else {
		clb_check_error(error, "clGetEventProfilingInfo");
	}
		
	double toMs = 1.0f / 1000000.0f;
	
	printf("event '%s':\n", description);
	printf("queued to submit = %f ms\n", (double)( submit - queued) * toMs);
	printf("submit to start = %f ms\n", (double)( start - queued ) * toMs);
	printf("start to end = %f ms\n", (double)( end - start ) * toMs);

}